<!doctype html>
<html>
<head>
<meta charset='UTF-8'><meta name='viewport' content='width=device-width initial-scale=1'>
<title>Python Function SDK user manual.md</title><link href='https://fonts.googleapis.com/css?family=Open+Sans:400italic,700italic,700,400&subset=latin,latin-ext' rel='stylesheet' type='text/css' /><style type='text/css'>html {overflow-x: initial !important;}#write, body { height: auto; }
#write, #write h1, #write h2, #write h3, #write h4, #write h5, #write h6, #write ol, #write p, #write ul { position: relative; }
#write, #write h1, #write h2, #write h3, #write h4, #write h5, #write h6, #write p, #write pre { width: inherit; }
#write, pre { white-space: pre-wrap; }
.CodeMirror, .md-fences, table { text-align: left; }
.md-reset, a:active, a:hover { outline: 0px; }
.md-reset, .md-toc-item a { text-decoration: none; }
.MathJax_SVG, .md-reset { float: none; direction: ltr; }
:root { --bg-color:#ffffff; --text-color:#333333; }
html { font-size: 14px; background-color: var(--bg-color); color: var(--text-color); font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; -webkit-font-smoothing: antialiased; }
body { margin: 0px; padding: 0px; bottom: 0px; top: 0px; left: 0px; right: 0px; font-size: 1rem; line-height: 1.42857; overflow-x: hidden; background: inherit; }
.in-text-selection, ::selection { background: rgb(181, 214, 252); text-shadow: none; }
#write { margin: 0px auto; word-break: normal; word-wrap: break-word; padding-bottom: 70px; overflow-x: visible; }
.first-line-indent #write p .md-line { text-indent: 0px; }
.first-line-indent #write li, .first-line-indent #write p, .first-line-indent #write p .md-line:first-child { text-indent: 2em; }
.for-image #write { padding-left: 8px; padding-right: 8px; }
body.typora-export { padding-left: 30px; padding-right: 30px; }
@media screen and (max-width: 500px) {
  body.typora-export { padding-left: 0px; padding-right: 0px; }
  .CodeMirror-sizer { margin-left: 0px !important; }
  .CodeMirror-gutters { display: none !important; }
}
#write > blockquote:first-child, #write > div:first-child, #write > ol:first-child, #write > p:first-child, #write > pre:first-child, #write > table:first-child, #write > ul:first-child { margin-top: 30px; }
#write li > table:first-child { margin-top: -20px; }
img { max-width: 100%; vertical-align: middle; }
button, input, select, textarea { color: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: inherit; line-height: inherit; font-family: inherit; }
input[type="checkbox"], input[type="radio"] { line-height: normal; padding: 0px; }
*, ::after, ::before { box-sizing: border-box; }
h1 { font-size: 2rem; }
h2 { font-size: 1.8rem; }
h3 { font-size: 1.6rem; }
h4 { font-size: 1.4rem; }
h5 { font-size: 1.2rem; }
h6 { font-size: 1rem; }
p { -webkit-margin-before: 1rem; -webkit-margin-after: 1rem; -webkit-margin-start: 0px; -webkit-margin-end: 0px; }
.mathjax-block { margin-top: 0px; margin-bottom: 0px; -webkit-margin-before: 0px; -webkit-margin-after: 0px; }
.hidden { display: none; }
.md-blockmeta { color: rgb(204, 204, 204); font-weight: 700; font-style: italic; }
a { cursor: pointer; }
sup.md-footnote { padding: 2px 4px; background-color: rgba(238, 238, 238, 0.7); color: rgb(85, 85, 85); border-radius: 4px; }
#write input[type="checkbox"] { cursor: pointer; width: inherit; height: inherit; }
#write > figure:first-child { margin-top: 16px; }
figure { overflow-x: auto; margin: -8px 0px 0px -8px; max-width: calc(100% + 16px); padding: 8px; }
tr { break-inside: avoid; break-after: auto; }
thead { display: table-header-group; }
table { border-collapse: collapse; border-spacing: 0px; width: 100%; overflow: auto; break-inside: auto; }
.CodeMirror-line, .md-fences { break-inside: avoid; }
table.md-table td { min-width: 80px; }
.CodeMirror-gutters { border-right: 0px; background-color: inherit; margin-right: 4px; }
.CodeMirror-placeholder { opacity: 0.3; }
.CodeMirror pre { padding: 0px 4px; }
.CodeMirror-lines { padding: 0px; }
div.hr:focus { cursor: none; }
.md-fences { font-size: 0.9rem; display: block; overflow: visible; white-space: pre; background: inherit; position: relative !important; }
.md-diagram-panel { width: 100%; margin-top: 10px; text-align: center; padding-top: 0px; padding-bottom: 8px; overflow-x: auto; }
.md-fences .CodeMirror.CodeMirror-wrap { top: -1.6em; margin-bottom: -1.6em; }
.md-fences.mock-cm { white-space: pre-wrap; }
.show-fences-line-number .md-fences { padding-left: 0px; }
.show-fences-line-number .md-fences.mock-cm { padding-left: 40px; }
.footnotes { opacity: 0.8; font-size: 0.9rem; margin-top: 1em; margin-bottom: 1em; }
.footnotes + .footnotes { margin-top: 0px; }
.md-reset { margin: 0px; padding: 0px; border: 0px; vertical-align: top; background: 0px 0px; text-shadow: none; position: static; width: auto; height: auto; white-space: nowrap; cursor: inherit; -webkit-tap-highlight-color: transparent; line-height: normal; font-weight: 400; text-align: left; box-sizing: content-box; }
.md-toc-inner, a img, img a { cursor: pointer; }
li div { padding-top: 0px; }
blockquote { margin: 1rem 0px; }
li .mathjax-block, li p { margin: 0.5rem 0px; }
li { margin: 0px; position: relative; }
blockquote > :last-child { margin-bottom: 0px; }
blockquote > :first-child { margin-top: 0px; }
.footnotes-area { color: rgb(136, 136, 136); margin-top: 0.714rem; padding-bottom: 0.143rem; white-space: nowrap; }
@media print {
  body, html { border: 1px solid transparent; height: 99%; break-after: avoid; break-before: avoid; }
  #write { margin-top: 0px; border-color: transparent !important; }
  .typora-export * { -webkit-print-color-adjust: exact; }
  h1, h2, h3, h4, h5, h6 { break-after: avoid-page; orphans: 2; }
  p { orphans: 4; }
  html.blink-to-pdf { font-size: 13px; }
  .typora-export #write { padding-left: 1cm; padding-right: 1cm; padding-bottom: 0px; break-after: avoid; }
  .typora-export #write::after { height: 0px; }
  @page { margin: 20mm 0px; }
}
.footnote-line { margin-top: 0.714em; font-size: 0.7em; }
pre.md-meta-block { font-size: 0.8rem; min-height: 0.8rem; white-space: pre-wrap; background: rgb(204, 204, 204); display: block; overflow-x: hidden; }
p > img:only-child { display: block; margin: auto; }
.md-line > .md-image:only-child, p > .md-image:only-child { display: inline-block; width: 100%; text-align: center; }
.mathjax-block:not(:empty)::after, .md-toc-content::after, .md-toc::after { display: none; }
#write .MathJax_Display { margin: 0.8em 0px 0px; }
.mathjax-block { white-space: pre; overflow: hidden; width: 100%; }
p + .mathjax-block { margin-top: -1.143rem; }
[contenteditable="true"]:active, [contenteditable="true"]:focus { outline: 0px; box-shadow: none; }
.md-task-list-item { position: relative; list-style-type: none; }
.task-list-item.md-task-list-item { padding-left: 0px; }
.md-task-list-item > input { position: absolute; top: 0px; left: 0px; margin-left: -1.2em; margin-top: calc(1em - 10px); }
.math { font-size: 1rem; }
.md-toc { min-height: 3.58rem; position: relative; font-size: 0.9rem; border-radius: 10px; }
.MathJax_SVG, .mathjax-block .MathJax_SVG_Display { text-indent: 0px; max-width: none; max-height: none; min-height: 0px; }
.md-toc-content { position: relative; margin-left: 0px; }
.md-toc-item { display: block; color: rgb(65, 131, 196); }
.md-toc-inner:hover { }
.md-toc-inner { display: inline-block; }
.md-toc-h1 .md-toc-inner { margin-left: 0px; font-weight: 700; }
.md-toc-h2 .md-toc-inner { margin-left: 2em; }
.md-toc-h3 .md-toc-inner { margin-left: 4em; }
.md-toc-h4 .md-toc-inner { margin-left: 6em; }
.md-toc-h5 .md-toc-inner { margin-left: 8em; }
.md-toc-h6 .md-toc-inner { margin-left: 10em; }
@media screen and (max-width: 48em) {
  .md-toc-h3 .md-toc-inner { margin-left: 3.5em; }
  .md-toc-h4 .md-toc-inner { margin-left: 5em; }
  .md-toc-h5 .md-toc-inner { margin-left: 6.5em; }
  .md-toc-h6 .md-toc-inner { margin-left: 8em; }
}
a.md-toc-inner { font-size: inherit; font-style: inherit; font-weight: inherit; line-height: inherit; }
.footnote-line a:not(.reversefootnote) { color: inherit; }
.md-attr { display: none; }
.md-fn-count::after { content: "."; }
code, pre, tt { font-family: var(--monospace); }
.md-comment { color: rgb(162, 127, 3); opacity: 0.8; font-family: var(--monospace); }
code { text-align: left; }
a.md-print-anchor { border-width: initial !important; border-style: none !important; border-color: initial !important; display: inline-block !important; position: absolute !important; width: 1px !important; right: 0px !important; outline: 0px !important; background: 0px 0px !important; text-decoration: initial !important; text-shadow: initial !important; }
.md-inline-math .MathJax_SVG .noError { display: none !important; }
.mathjax-block .MathJax_SVG_Display { text-align: center; margin: 1em 0px; position: relative; min-width: 100%; width: auto; display: block !important; }
.MathJax_SVG_Display, .md-inline-math .MathJax_SVG_Display { width: auto; margin: inherit; display: inline-block !important; }
.MathJax_SVG .MJX-monospace { font-family: monospace; }
.MathJax_SVG .MJX-sans-serif { font-family: sans-serif; }
.MathJax_SVG { display: inline; font-style: normal; font-weight: 400; line-height: normal; zoom: 90%; text-align: left; text-transform: none; letter-spacing: normal; word-spacing: normal; word-wrap: normal; white-space: nowrap; min-width: 0px; border: 0px; padding: 0px; margin: 0px; }
.MathJax_SVG * { transition: none; }
.os-windows.monocolor-emoji .md-emoji { font-family: "Segoe UI Symbol", sans-serif; }
.md-diagram-panel > svg, [lang="flow"] svg, [lang="mermaid"] svg { max-width: 100%; }
[lang="mermaid"] .node text { font-size: 1rem; }
table tr th { border-bottom: 0px; }


:root { --side-bar-bg-color: #fafafa; --control-text-color: #777; }
@font-face { font-family: "Open Sans"; font-style: normal; font-weight: normal; src: local("Open Sans Regular"), url("./github/400.woff") format("woff"); }
@font-face { font-family: "Open Sans"; font-style: italic; font-weight: normal; src: local("Open Sans Italic"), url("./github/400i.woff") format("woff"); }
@font-face { font-family: "Open Sans"; font-style: normal; font-weight: bold; src: local("Open Sans Bold"), url("./github/700.woff") format("woff"); }
@font-face { font-family: "Open Sans"; font-style: italic; font-weight: bold; src: local("Open Sans Bold Italic"), url("./github/700i.woff") format("woff"); }
html { font-size: 16px; }
body { font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif; color: rgb(51, 51, 51); line-height: 1.6; }
#write { max-width: 860px; margin: 0px auto; padding: 20px 30px 100px; }
#write > ul:first-child, #write > ol:first-child { margin-top: 30px; }
body > :first-child { margin-top: 0px !important; }
body > :last-child { margin-bottom: 0px !important; }
a { color: rgb(65, 131, 196); }
h1, h2, h3, h4, h5, h6 { position: relative; margin-top: 1rem; margin-bottom: 1rem; font-weight: bold; line-height: 1.4; cursor: text; }
h1:hover a.anchor, h2:hover a.anchor, h3:hover a.anchor, h4:hover a.anchor, h5:hover a.anchor, h6:hover a.anchor { text-decoration: none; }
h1 tt, h1 code { font-size: inherit; }
h2 tt, h2 code { font-size: inherit; }
h3 tt, h3 code { font-size: inherit; }
h4 tt, h4 code { font-size: inherit; }
h5 tt, h5 code { font-size: inherit; }
h6 tt, h6 code { font-size: inherit; }
h1 { padding-bottom: 0.3em; font-size: 2.25em; line-height: 1.2; border-bottom: 1px solid rgb(238, 238, 238); }
h2 { padding-bottom: 0.3em; font-size: 1.75em; line-height: 1.225; border-bottom: 1px solid rgb(238, 238, 238); }
h3 { font-size: 1.5em; line-height: 1.43; }
h4 { font-size: 1.25em; }
h5 { font-size: 1em; }
h6 { font-size: 1em; color: rgb(119, 119, 119); }
p, blockquote, ul, ol, dl, table { margin: 0.8em 0px; }
li > ol, li > ul { margin: 0px; }
hr { height: 4px; padding: 0px; margin: 16px 0px; background-color: rgb(231, 231, 231); border-width: 0px 0px 1px; border-style: none none solid; border-top-color: initial; border-right-color: initial; border-left-color: initial; border-image: initial; overflow: hidden; box-sizing: content-box; border-bottom-color: rgb(221, 221, 221); }
body > h2:first-child { margin-top: 0px; padding-top: 0px; }
body > h1:first-child { margin-top: 0px; padding-top: 0px; }
body > h1:first-child + h2 { margin-top: 0px; padding-top: 0px; }
body > h3:first-child, body > h4:first-child, body > h5:first-child, body > h6:first-child { margin-top: 0px; padding-top: 0px; }
a:first-child h1, a:first-child h2, a:first-child h3, a:first-child h4, a:first-child h5, a:first-child h6 { margin-top: 0px; padding-top: 0px; }
h1 p, h2 p, h3 p, h4 p, h5 p, h6 p { margin-top: 0px; }
li p.first { display: inline-block; }
ul, ol { padding-left: 30px; }
ul:first-child, ol:first-child { margin-top: 0px; }
ul:last-child, ol:last-child { margin-bottom: 0px; }
blockquote { border-left: 4px solid rgb(221, 221, 221); padding: 0px 15px; color: rgb(119, 119, 119); }
blockquote blockquote { padding-right: 0px; }
table { padding: 0px; word-break: initial; }
table tr { border-top: 1px solid rgb(204, 204, 204); margin: 0px; padding: 0px; }
table tr:nth-child(2n) { background-color: rgb(248, 248, 248); }
table tr th { font-weight: bold; border-width: 1px 1px 0px; border-top-style: solid; border-right-style: solid; border-left-style: solid; border-top-color: rgb(204, 204, 204); border-right-color: rgb(204, 204, 204); border-left-color: rgb(204, 204, 204); border-image: initial; border-bottom-style: initial; border-bottom-color: initial; text-align: left; margin: 0px; padding: 6px 13px; }
table tr td { border: 1px solid rgb(204, 204, 204); text-align: left; margin: 0px; padding: 6px 13px; }
table tr th:first-child, table tr td:first-child { margin-top: 0px; }
table tr th:last-child, table tr td:last-child { margin-bottom: 0px; }
.CodeMirror-gutters { border-right: 1px solid rgb(221, 221, 221); }
.md-fences, code, tt { border: 1px solid rgb(221, 221, 221); background-color: rgb(248, 248, 248); border-radius: 3px; font-family: Consolas, "Liberation Mono", Courier, monospace; padding: 2px 4px 0px; font-size: 0.9em; }
.md-fences { margin-bottom: 15px; margin-top: 15px; padding: 8px 1em 6px; }
.md-task-list-item > input { margin-left: -1.3em; }
@media screen and (min-width: 914px) {
}
@media print {
  html { font-size: 13px; }
  table, pre { break-inside: avoid; }
  pre { word-wrap: break-word; }
}
.md-fences { background-color: rgb(248, 248, 248); }
#write pre.md-meta-block { padding: 1rem; font-size: 85%; line-height: 1.45; background-color: rgb(247, 247, 247); border: 0px; border-radius: 3px; color: rgb(119, 119, 119); margin-top: 0px !important; }
.mathjax-block > .code-tooltip { bottom: 0.375rem; }
#write > h3.md-focus::before { left: -1.5625rem; top: 0.375rem; }
#write > h4.md-focus::before { left: -1.5625rem; top: 0.285714rem; }
#write > h5.md-focus::before { left: -1.5625rem; top: 0.285714rem; }
#write > h6.md-focus::before { left: -1.5625rem; top: 0.285714rem; }
.md-image > .md-meta { border-radius: 3px; font-family: Consolas, "Liberation Mono", Courier, monospace; padding: 2px 0px 0px 4px; font-size: 0.9em; color: inherit; }
.md-tag { color: inherit; }
.md-toc { margin-top: 20px; padding-bottom: 20px; }
.sidebar-tabs { border-bottom: none; }
#typora-quick-open { border: 1px solid rgb(221, 221, 221); background-color: rgb(248, 248, 248); }
#typora-quick-open-item { background-color: rgb(250, 250, 250); border-color: rgb(254, 254, 254) rgb(229, 229, 229) rgb(229, 229, 229) rgb(238, 238, 238); border-style: solid; border-width: 1px; }
#md-notification::before { top: 10px; }
.on-focus-mode blockquote { border-left-color: rgba(85, 85, 85, 0.12); }
header, .context-menu, .megamenu-content, footer { font-family: "Segoe UI", Arial, sans-serif; }
.file-node-content:hover .file-node-icon, .file-node-content:hover .file-node-open-state { visibility: visible; }
.mac-seamless-mode #typora-sidebar { background-color: var(--side-bar-bg-color); }
.md-lang { color: rgb(180, 101, 77); }
.html-for-mac .context-menu { --item-hover-bg-color: #E6F0FE; }





 .typora-export p {white-space: normal;} 
</style>
</head>
<body class='typora-export' >
<div  id='write'  class = 'is-node'><h3><a name='header-n0' class='md-header-anchor '></a>Python Function SDK 说明文档</h3><h4><a name='header-n2' class='md-header-anchor '></a>1. 概述</h4><p>Python Function SDK是EwayOS的编程接口SDK，主要包含emake、文档、example部分。 </p><p>在编写PythonFunction时，建议使用Pycharm进行编程。</p><h4><a name='header-n7' class='md-header-anchor '></a>2. Function结构介绍</h4><p>Function是EwayOS中的具体功能层，Function连接HighLevelAI获取机器人检测消息，连接LowLevelAI获得机器人运动控制。Function框架主要机制如下：</p><h5><a name='header-n10' class='md-header-anchor '></a>(1) Message机制</h5><p>Function内部使用MessageList机制，所有消息（包含HighLevelAI检测到的周边数据，LowLevelAI发送的运动数据以及Function内部的Timer数据、自定义消息数据）均按到达时间及优先级加入一个消息队列，每个Function内部均存在在一个消息处理线程，该线程读取此消息列表，串行处理各消息。</p><h5><a name='header-n13' class='md-header-anchor '></a>(2) Feature机制</h5><p>Feature为Function向HighLevelAI请求某项识别、检测功能所使用。Function欲开启某项识别或检测功能时，需在<a href='PyFunctionInterface/initialize.html'>initialize</a>时或Function运行的任何时间内调用<a href='PyFunctionInterface/request_feature.html'>request_feature</a>请求Feature，请求成功后Function模块即会收到对应的识别、检测消息，此时调用<a href='PyFunctionInterface/set_message_receive_type.html'>set_message_receive_type</a>方法可以设置对应消息的接收类型，若未进行设置则消息的接收类型默认为:MsgProcCode_Notify，框架回调用对应的proc开头的函数进行回调通知;  若设置为MsgProcCode_Record，框架会将消息数据存储，Python Function模块可调用[get_message_data]函数获取最新一次消息数据。</p><p>所有请求成功的Feature应在不需要该功能时再次调用<a href='PyFunctionInterface/request_feature.html'>request_feature</a>关闭。</p><p>关闭Feature应在<a href='PyFunctionInterface/job_start.html'>job_start</a>后，若请求Feature成功后HighLevelAI掉线，Function不需重新请求Feature，框架会在HighLevelAI上线后自动重新请求。</p><p>若在Function请求Feature成功后，由于Sensor原因造成Feature检测错误，Function会收到<a href='PyFunctionInterface/proc_feature_status.html'>proc_feature_status</a>回调。</p><p>目前支持的<a href='FeatureList.html'>feature_code</a>。</p><h5><a name='header-n24' class='md-header-anchor '></a>(3) Initialize机制</h5><p>Function在启动时必须要初始化资源，等资源初始化完成之后，系统会调入<a href='PyFunctionInterface/job_start.html'>job_start</a>函数，开始Function真正的工作。</p><p><a href='PyFunctionInterface/initialize.html'>initialize</a>为Function初始化函数，它有三个参数，feature_list, (需要申请的资源列表)、limb_authority(机器人肢体控制权)和time_out(Function等待框架处理申请的时间(s))。用户需要填入本Function能正常运行所需要的所有Feature和肢体请求权限，等系统申请成功后会自动调入job_start中，如果系统没有申请成功且time_out没有赋值，则Function会处于一直等待的状态；如果申请没有成功但time_out有赋值，则会在等待时间后进入<a href='PyFunctionInterface/job_failed.html'>job_failed</a>。</p><p>如果在初始化时，没有填入任何Feature并且没有把limb_authority设置为true，表示Function不需要Sensor的Feature数据和LowLevelAI的肢体控制权，系统会直接调入job_start中，开始Function的工作。</p><h5><a name='header-n31' class='md-header-anchor '></a>(4) Command机制</h5><p>Command为Function向LowLevelAI发送运动指令，控制机器人运动所使用。</p><p>Command欲控制机器人运动时，可发送运动命令。LowLevelAI收到运动控制函数后，首先检查权限，权限正常后及发送返回值至Function，运动函数返回，此时机器人还未开始运动，之后LowLevelAI开始规划运动轨迹，发送电机指令控制机器人运动。当指令发送完毕，等待下位机执行结束后，LowLevelAI会发送<a href='Messages/CmdDoneMessage.html'>command_done</a>消息至Function，通知Function该指令执行完毕。Function使用commnad_sn识别<a href='Messages/CmdDoneMessage.html'>command_done</a>与之前发送的运动指令。</p><p>若在Function请求肢体控制权成功后，由于LowLevelAI下线或其它高优先级Function上下线原因造成肢体控制权变化，Function会收到<a href='PyFunctionInterface/proc_authority_message.html'>proc_authority_message</a>回调。</p><h5><a name='header-n38' class='md-header-anchor '></a><em>备注：</em></h5><ol start='' ><li><a href='Messages/CmdDoneMessage.html'>command_done</a>)消息可能会传递执行失败消息，（command_status不为0）。此时command_status变量存储错误码。</li><li>对于控制电机速度系列指令（<a href='PyFunctionInterface/wheel_straight_speed.html'>wheel_straight_speed</a>，<a href='PyFunctionInterface/wheel_cycle_speed.html'>wheel_cycle_speed</a>，<a href='Messages/CmdDoneMessage.html'>command_done</a>)消息会立刻发出，指令若未被后续指令取消，会持续执行2.4s。 </li></ol><h5><a name='header-n46' class='md-header-anchor '></a>(5) 子Function机制</h5><p>Python Function提供加载两种Function的方式，一种是加载Python Function <a href='PyFunctionInterface/add_child_function.html'>add_child_function</a> , 一种是加载C编写的Function <a href='PyFunctionInterface/add_clib_function.html'>add_clib_function</a> 。两种方式下框架都会自动实例化该子Function模块，将其连入HighLevelAI及LowLevelAI，子Function可获取消息数据，可发送肢体控制指令控制机器人运动。</p><p>父Function与子Function通过参数进行通信。在加载子Function时,提供传递字符串给子Function，子Function收到参数后框架会调用<a href='PyFunctionInterface/proc_parameter_message.html'>proc_parameter_message</a>进行通知。</p><p>Python版的子Function退出可选择两种方式，主动退出或被动退出。主动退出为子Function任务执行完毕，关闭Feature及肢体控制权，显式调用<a href='PyFunctionInterface/function_quit.html'>function_quit</a>函数通知父Function退出。调用<a href='PyFunctionInterface/function_quit.html'>function_quit</a>后，框架回调用子Function的<a href='PyFunctionInterface/Uninitialize.html'>Uninitialize</a>函数，之后关闭消息处理线程，子Function退出。框架会调用父Function的<a href='PyFunctionInterface/proc_child_quit.html'>proc_child_quit</a>回调通知父Function。被动退出为父Function调用<a href='PyFunctionInterface/post_stop_command_to_child.html'>post_stop_command_to_child</a>或<a href='PyFunctionInterface/post_stop_command_to_all_child.html'>post_stop_command_to_all_child</a>函数通知子Function退出，框架会调用子Function的<a href='PyFunctionInterface/proc_close_cmd_message.html'>proc_close_cmd_message</a>回调通知子Function，此时子Function应立刻关闭Feature及肢体控制权，关闭timer，尽快调用<a href='PyFunctionInterface/function_quit.html'>function_quit</a>退出。调用function_quit之后的流程与主动退出相同。</p><p>子Function推出后可传递字符串参数给父Function。</p><h5><a name='header-n55' class='md-header-anchor '></a>(6) Timer机制</h5><p>Function可使用<a href='PyFunctionInterface/set_timer.html'>set_timer</a>函数开关计时器，参数为间隔ms数。当间隔时间到达后，框架会向Function消息队列中插入一条Timer事件，当消息处理线程处理此消息时，会调用<a href='PyFunctionInterface/proc_timer.html'>proc_timer</a>函数进行处理。</p><p><strong><em>注：</em></strong></p><p>此Timer为非精准Timer，时间间隔为传递消息的最小时间间隔。</p><p>若由于程序问题造成消息处理线程响应不及时，可能会造成Timer事件在队列中累计，出现一个时段无<a href='PyFunctionInterface/proc_timer.html'>proc_timer</a>，另一时段<a href='PyFunctionInterface/proc_timer.html'>proc_timer</a>函数频繁调用。</p><h4><a name='header-n65' class='md-header-anchor '></a>3. 编程接口说明</h4><h5><a name='header-n66' class='md-header-anchor '></a>(1) <a href='PyFunctionInterface/initialize.html'>initialize</a></h5><p>模块初始化函数，此函数会在所有函数调用前调用，在这里填入Function运行里所需要的资源。</p><h5><a name='header-n69' class='md-header-anchor '></a>(2)<a href='PyFunctionInterface/destroy.html'>destroy</a></h5><p>模块销毁函数，此函数会在销毁前最后一个调用。</p><h5><a name='header-n72' class='md-header-anchor '></a>(3) <a href='PyFunctionInterface/set_message_receive_type.html'>set_message_receive_type</a></h5><p>设置消息处理方式。返回值可选择方式如下： 
MsgProcCode_Notify，MsgProcCode_Record.</p><h5><a name='header-n76' class='md-header-anchor '></a>(4) <a href='PyFunctionInterface/job_start.html'>job_start</a></h5><p>初始化完后自动调入，表示Function 开始工作。 </p><h5><a name='header-n79' class='md-header-anchor '></a>(5) <a href='PyFunctionInterface/job_failed.html'>job_failed</a></h5><p>初始化失败，Function结束工作。 </p><h5><a name='header-n82' class='md-header-anchor '></a>(6) <a href='PyFunctionInterface/set_timer.html'>set_timer</a></h5><p>开启或关闭一个定时器。</p><h5><a name='header-n85' class='md-header-anchor '></a>(7) <a href='PyFunctionInterface/proc_timer.html'>proc_timer</a></h5><p>定时器触发通知。</p><h5><a name='header-n88' class='md-header-anchor '></a>(8) <a href='PyFunctionInterface/add_clib_function.html'>add_clib_function</a></h5><p>调用其它Function模块（Function动态库）。该函数可加载其它编写好的Function动态库，被调用动态库将使用此Function进程所拥有的HighLevelAI及LowLevelAI连接，获取机器人数据以及控制机器人运动。</p><h5><a name='header-n91' class='md-header-anchor '></a>(9) <a href='PyFunctionInterface/add_child_function.html'>add_child_function</a></h5><p>加载其它的Python Function。</p><h5><a name='header-n94' class='md-header-anchor '></a>(10) <a href='PyFunctionInterface/post_stop_command_to_all_child.html'>post_stop_command_to_all_child</a></h5><p>向所有子Function发送Close指令</p><h5><a name='header-n97' class='md-header-anchor '></a>(11) <a href='PyFunctionInterface/post_stop_command_to_child.html'>post_stop_command_to_child</a></h5><p>向某一子Function发送Close指令 </p><h5><a name='header-n100' class='md-header-anchor '></a>(12) <a href='PyFunctionInterface/function_quit.html'>function_quit</a></h5><p>向父Funtion发送关闭通知。</p><h5><a name='header-n103' class='md-header-anchor '></a>(13) <a href='PyFunctionInterface/proc_child_quit.html'>proc_child_quit</a></h5><p>子Function退出回调，此Function模块调用的某一子Function已运行结束。</p><h5><a name='header-n106' class='md-header-anchor '></a>(14) <a href='PyFunctionInterface/proc_close_cmd_message.html'>proc_close_cmd_message</a></h5><p>收到父Function或框架发送的关闭指令。</p><h5><a name='header-n109' class='md-header-anchor '></a>(15) <a href='PyFunctionInterface/request_feature.html'>request_feature</a></h5><p>向HighLevelAI发送消息通知请求。发送此命令应在HighLevelAI上线后。</p><h5><a name='header-n112' class='md-header-anchor '></a>(16) <a href='PyFunctionInterface/proc_voice_message.html'>proc_voice_message</a></h5><p>收到语音识别消息回调</p><h5><a name='header-n115' class='md-header-anchor '></a>(17) <a href='PyFunctionInterface/proc_object_message.html'>proc_object_message</a></h5><p>收到物体识别消息回调</p><h5><a name='header-n118' class='md-header-anchor '></a>(18) <a href='PyFunctionInterface/proc_marker_message.html'>proc_marker_message</a></h5><p>收到Marker识别消息回调</p><h5><a name='header-n121' class='md-header-anchor '></a>(19) <a href='PyFunctionInterface/proc_face_message.html'>proc_face_message</a></h5><p>收到人脸识别或检测消息回调</p><h5><a name='header-n124' class='md-header-anchor '></a>(20) <a href='PyFunctionInterface/proc_sonar_message.html'>proc_sonar_message</a></h5><p>收到声纳障碍检测消息回调</p><h5><a name='header-n127' class='md-header-anchor '></a>(21) <a href='PyFunctionInterface/proc_laser_message.html'>proc_laser_message</a></h5><p>收到激光雷达障碍检测消息回调</p><h5><a name='header-n130' class='md-header-anchor '></a>(22) <a href='PyFunctionInterface/proc_arm_position.html'>proc_arm_position</a></h5><p>收到手臂移动消息回调</p><h5><a name='header-n133' class='md-header-anchor '></a>(23) <a href='PyFunctionInterface/proc_robot_position.html'>proc_robot_position</a></h5><p>收到位置移动消息回调</p><h5><a name='header-n136' class='md-header-anchor '></a>(24) <a href='PyFunctionInterface/proc_head_position.html'>proc_head_position</a></h5><p>收到头部移动消息回调</p><h5><a name='header-n139' class='md-header-anchor '></a>(25) <a href='PyFunctionInterface/proc_imu_message.html'>proc_imu_message</a></h5><p>收到IMU的数据</p><h5><a name='header-n142' class='md-header-anchor '></a>(26) <a href='PyFunctionInterface/proc_feature_status.html'>proc_feature_status</a></h5><p>HighLevel中Feature状态改变通知。此消息一般由Sensor状态改变触发。</p><h5><a name='header-n145' class='md-header-anchor '></a>(27) <a href='PyFunctionInterface/request_authority.html'>request_authority</a></h5><p>向LowLevelAI发送肢体控制请求。此命令应在LowLevelAI上线后发送。</p><h5><a name='header-n148' class='md-header-anchor '></a>(28) <a href='PyFunctionInterface/proc_authority_message.html'>proc_authority_message</a></h5><p>LowLevelAI发送的肢体控制权变化。</p><h5><a name='header-n151' class='md-header-anchor '></a>(29) <a href='PyFunctionInterface/proc_cmd_done_message.html'>proc_cmd_done_message</a></h5><p>Function发送的肢体命令已响应完毕，肢体运动结束。</p><h5><a name='header-n154' class='md-header-anchor '></a>(30) <a href='PyFunctionInterface/speaker_play_text.html'>speaker_play_text</a></h5><p>发送speaker_play_text指令至LowLevelAI，机器人将运行Text To Speech模块进行语音转换并播放。</p><h5><a name='header-n157' class='md-header-anchor '></a>(31) <a href='PyFunctionInterface/head_move.html'>head_move</a></h5><p>发送head_move指令至LowLevelAI，机器人将根据指令数据移动头部。</p><h5><a name='header-n160' class='md-header-anchor '></a>(32) <a href='PyFunctionInterface/head_move_sync.html'>head_move_sync</a></h5><p>发送head_move_sync指令至LowLevelAI，机器人将根据指令数据移动头部</p><h5><a name='header-n163' class='md-header-anchor '></a>(33) <a href='PyFunctionInterface/head_stop.html'>head_stop</a></h5><p>发送head_stop指令至LowLevelAI，机器人将根据指令立刻停止头部运动。</p><h5><a name='header-n166' class='md-header-anchor '></a>(34) <a href='PyFunctionInterface/wheel_goto_position.html'>wheel_goto_position</a></h5><p>发送wheel_goto_position指令至LowLevelAI，机器人底盘将根据目标点进行运动。</p><h5><a name='header-n169' class='md-header-anchor '></a>(35) <a href='PyFunctionInterface/wheel_brake.html'>wheel_brake</a></h5><p>发送wheel_brake指令至LowLevelAI，机器人双轮立即进行减速刹车。</p><h5><a name='header-n172' class='md-header-anchor '></a>(36) <a href='PyFunctionInterface/wheel_straight.html'>wheel_straight</a></h5><p>发送wheel_straight指令至LowLevelAI，机器人底盘将进行位置模式的直线运动。</p><h5><a name='header-n175' class='md-header-anchor '></a>(37) <a href='PyFunctionInterface/wheel_straight_speed.html'>wheel_straight_speed</a></h5><p>发送wheel_straight_speed指令至LowLevelAI，机器人将按指令进行直线速度运动。</p><h5><a name='header-n178' class='md-header-anchor '></a>(38) <a href='PyFunctionInterface/wheel_cycle.html'>wheel_cycle</a></h5><p>发送wheel_cycle指令至LowLevelAI，机器人底盘进行位置模式的弧线运动。</p><h5><a name='header-n181' class='md-header-anchor '></a>(39) <a href='PyFunctionInterface/wheel_cycle_speed.html'>wheel_cycle_speed</a></h5><p>发送wheel_cycle_speed指令至LowLevelAI，机器人底盘会进行速度模式的弧线运动。</p><h5><a name='header-n184' class='md-header-anchor '></a>(40) <a href='PyFunctionInterface/wheel_trans_rot_speed.html'>wheel_trans_rot_speed</a></h5><p>发送wheel_trans_rot_speed指令至LowLevelAI，机器人底盘会以给定的角速度线速度运动。</p><h5><a name='header-n187' class='md-header-anchor '></a>(41) <a href='PyFunctionInterface/arm_follow_trajectory.html'>arm_follow_trajectory</a></h5><p>发送arm_follow_trajectory指令至LowLevelAI，机器人将根据轨迹文件进行手臂运动。</p><h5><a name='header-n190' class='md-header-anchor '></a>(42) <a href='PyFunctionInterface/arm_move_angle.html'>arm_move_angle</a></h5><p>发送arm_move_angle指令至LowLevelAI，机器人手臂将依照指定速度运动至指定角度。</p><h5><a name='header-n193' class='md-header-anchor '></a>(43) <a href='PyFunctionInterface/arm_move_angle_sync.html'>arm_move_angle_sync</a></h5><p>发送arm_move_angle_sync指令至LowLevelAI，机器人手臂将依照指定时间运动至指定角度。</p><h5><a name='header-n196' class='md-header-anchor '></a>(44) <a href='PyFunctionInterface/arm_move_gripper.html'>arm_move_gripper</a></h5><p>发送arm_move_gripper指令至LowLevelAI，机器人末端执行器将以默认速度运动至指定位置。</p><h5><a name='header-n199' class='md-header-anchor '></a>(45) <a href='PyFunctionInterface/arm_stop.html'>arm_stop</a></h5><p>发送arm_stop指令至LowLevelAI，机器人手臂将停止运动并静止在当前位置。</p><h5><a name='header-n202' class='md-header-anchor '></a>(46) <a href='PyFunctionInterface/obstacle_avoid.html'>obstacle_avoid</a></h5><p>发送obstacle_avoid指令至LowLevelAI，打开或者关闭机器人避障。</p><h5><a name='header-n205' class='md-header-anchor '></a>(47) <a href='PyFunctionInterface/get_marker_message.html'>get_marker_message</a></h5><p>获取marker数据。</p><h5><a name='header-n208' class='md-header-anchor '></a>(48) <a href='PyFunctionInterface/get_face_message.html'>get_face_message</a></h5><p>获取face数据。</p><h5><a name='header-n211' class='md-header-anchor '></a>(49) <a href='PyFunctionInterface/get_object_message.html'>get_object_message</a></h5><p>获取object数据。</p><h5><a name='header-n214' class='md-header-anchor '></a>(50) <a href='PyFunctionInterface/get_voice_message.html'>get_voice_message</a></h5><p>获取voice数据。</p><h5><a name='header-n217' class='md-header-anchor '></a>(51) <a href='PyFunctionInterface/get_robot_position.html'>get_robot_position</a></h5><p>获取robot_position数据。</p><h5><a name='header-n220' class='md-header-anchor '></a>(52) <a href='PyFunctionInterface/get_head_position.html'>get_head_position</a></h5><p>获取head_position数据。</p><h5><a name='header-n223' class='md-header-anchor '></a>(53) <a href='PyFunctionInterface/get_sonar_message.html'>get_sonar_message</a></h5><p>获取sonar数据。</p><h5><a name='header-n226' class='md-header-anchor '></a>(54) <a href='PyFunctionInterface/get_laser_message.html'>get_laser_message</a></h5><p>获取laser数据。</p><h5><a name='header-n229' class='md-header-anchor '></a>(55) <a href='PyFunctionInterface/get_imu_message.html'>get_imu_message</a></h5><p>获取imu数据。</p><h5><a name='header-n232' class='md-header-anchor '></a>(56) <a href='PyFunctionInterface/get_arm_position.html'>get_arm_position</a></h5><p>获取手臂位置信息。</p><h5><a name='header-n235' class='md-header-anchor '></a>(57) <a href='PyFunctionInterface/leg_stop.html'>leg_stop</a></h5><p>发送指令，使腿部停止运动</p><h5><a name='header-n238' class='md-header-anchor '></a>(58) <a href='PyFunctionInterface/leg_follow_trajectory.html'>leg_follow_trajectory</a></h5><p>根据轨迹文件进行相应的运动。</p><h5><a name='header-n241' class='md-header-anchor '></a>(59) <a href='PyFunctionInterface/leg_move_angle.html'>leg_move_angle</a></h5><p>依照指定速度运动至指定角度。</p><h5><a name='header-n244' class='md-header-anchor '></a>(60) <a href='PyFunctionInterface/proc_leg_position.html'>proc_leg_position</a></h5><p>获取腿部位置信息。</p><h4><a name='header-n247' class='md-header-anchor '></a>4. 错误码</h4><p>系统提供了对于不同错误的描述，帮助开发者更好的定位问题，<a href='../../OS/EwayOSErrCode.html'>详见</a>。</p></div>
</body>
</html>